<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <hr />
    <input type="text" v-model="firstName" />
    <div>firstName: {{ firstName }}</div>
    <input type="text" v-model="lastName" />
    <div>lastName: {{ lastName }}</div>
    <input type="text" v-model="age" />
    <div>age: {{ age }}</div>
    <div>intro: {{ intro }}</div>
  </div>
</template>

<script>
import { ref, watch, watchEffect } from "vue";
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  setup() {
    const firstName = ref("尼古拉斯");
    const lastName = ref("赵四");
    const age = ref(26);
    // 个人介绍
    const intro = ref("");

    // 一次监听多个参数
    // watch([firstName, lastName, age], (nval, oval) => {
    //   intro.value = `我叫${ nval[0] }-${ nval[1] },今年${ nval[2] }岁`
    // }, { immediate: true })

    watchEffect(() => {
      intro.value = `我叫${firstName.value}-${lastName.value},今年${age.value}岁`;
    });

    return {
      firstName,
      lastName,
      age,
      intro,
    };
  },
};
</script>

<style scoped>
</style>
